#include <stdio.h>
#include <memory>

typedef struct _StructA StructA;
typedef struct _StructB StructB;

struct _StructA
{
    int i;
    std::shared_ptr<StructB> pStructB;
    _StructA() : i(int())
    {
        printf("_StructA alloc \n");
    };

    ~_StructA()
    {
        printf("_StructA dealloc \n");
    };
};

struct _StructB
{
    int i;
    std::shared_ptr<StructA> pStructA;
    _StructB() : i(int())
    {
        printf("_StructB alloc \n");
    };

    ~_StructB()
    {
        printf("_StructB dealloc \n");
    };
};

void funPre()
{

    printf("----- start ----- \n");
    {
        std::shared_ptr<StructA> pA = std::make_shared<StructA>();
        std::shared_ptr<StructB> pB = std::make_shared<StructB>();
        pA->pStructB = pB;
        pB->pStructA = pA;
    }
    printf("----- end ----- \n\n");
}
int main(int argc, const char *argv[])
{

    printf("\n----- start ----- \n");
    {
        std::shared_ptr<StructA> pA = std::make_shared<StructA>();
        std::shared_ptr<StructB> pB(new StructB());
    }
    printf("----- end ----- \n");

    printf("\n----- 环形引用 ----- \n\n");
    funPre();
    return 0;
}